﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;
using FrameworkManapro.Utilities;
using FrameworkManapro.WebUI;

namespace GMAC.ReportingSystem.Business.Components
{
    public class FieldRepComponent : IBusinessComponent<Entities.FieldRep>
    {
         private DataAccess.FieldRepDataAccess dac;

        public FieldRepComponent()
        {
            dac = new DataAccess.FieldRepDataAccess();
        }

        #region IBusinessComponent<FieldRep> Members

        public int Create(Entities.FieldRep entityToCreate)
        {
            if (Validate(entityToCreate))
            {
                var result = dac.Insert(entityToCreate);
                return result;
            }
            return 0;
        }

        public int Delete(Entities.FieldRep entityToDelete)
        {
            if (entityToDelete.ID <= 0)
                throw new ArgumentOutOfRangeException("FieldRepID", "Value must be greater than zero.");

            return dac.Delete(entityToDelete);
        }

        public int Edit(Entities.FieldRep entityToEdit)
        {
            if (entityToEdit.ID <= 0)
                throw new ArgumentOutOfRangeException("FieldRepID", "Value must be greater than zero.");

            return Validate(entityToEdit) ? dac.Update(entityToEdit) : 0;
        }

        public Entities.FieldRep GetDetails(object entityId)
        {
            return dac.Get(entityId);
        }

        protected bool Validate(Entities.FieldRep FieldRep)
        {
            if (FieldRep == null) throw new ArgumentNullException("FieldRep", "The argument cannot be null.");
            if (string.IsNullOrEmpty(FieldRep.ID.ToString())) throw new ArgumentNullException("ID", "The argument cannot be null.");
            if (string.IsNullOrEmpty(FieldRep.Status.ToString())) throw new ArgumentNullException("Status", "The argument cannot be null.");
            if (string.IsNullOrEmpty(FieldRep.Type.ToString())) throw new ArgumentNullException("Type", "The argument cannot be null.");
            if (string.IsNullOrEmpty(FieldRep.Name)) throw new ArgumentNullException("Name", "The argument canno be null.");

            return true;
        }

        #endregion

      
        public Entities.FieldRepCollection GetList()
        {
            return dac.GetList();
        }

        public Entities.FieldRepCollection Search(int? id, string name, int? type, PagingDetails paging)
        {
            if (name == null) name = string.Empty;
            return dac.Search(id, name, type, paging);
        }

     

    }
}
